/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.sadhar.sipp.perekamanrapatkerja;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.sadhar.cektabel.cekTabel;
import org.sadhar.cektabel.cekTabelDAO;
import org.sadhar.cektabel.cekTabelDAOImpl;
import org.sadhar.sia.common.ClassConnection;
import org.sadhar.sia.common.ClassUtility;

/**
 *
 * @author hendro
 */
public class PerekamanRapatKerjaDAOImpl implements PerekamanRapatKerjaDAO {

    public PerekamanRapatKerjaDAOImpl() {
        ClassConnection.getTransactionProxyFactoryBean().setTarget(this);
    }

    public List<PerekamanRapatKerja> list() {
        List<Map> list = ClassConnection.getJdbc().queryForList("SELECT * FROM ppmk.rapatKerja");
        List<PerekamanRapatKerja> data = new ArrayList<PerekamanRapatKerja>();
        for (Map m : list) {
            PerekamanRapatKerja prk = new PerekamanRapatKerja();
            prk.setKodeRapatKerja(Integer.valueOf(m.get("kodeRapatKerja").toString()));
            prk.setNamaRapatKerja(m.get("namaRapatKerja").toString());
            data.add(prk);
        }
        return data;
    }

    public void insert(PerekamanRapatKerja rapat) throws Exception {
        String sql = "INSERT INTO ppmk.rapatKerja(namaRapatKerja) VALUES(?)";
        ClassConnection.getJdbc().update(sql, new Object[]{ClassUtility.quote(rapat.getNamaRapatKerja())});
    }

    public void delete(PerekamanRapatKerja rapat) throws Exception {
        String sql = "DELETE FROM ppmk.rapatKerja WHERE kodeRapatKerja=?";
        ClassConnection.getJdbc().update(sql, new Object[]{Integer.valueOf(rapat.getKodeRapatKerja())});
    }

    public void update(PerekamanRapatKerja rapat) throws Exception {
        String sql = "UPDATE ppmk.rapatKerja SET namaRapatKerja=? WHERE kodeRapatKerja=?";
        ClassConnection.getJdbc().update(sql, new Object[]{ClassUtility.quote(rapat.getNamaRapatKerja()),
                    Integer.valueOf(rapat.getKodeRapatKerja())});
    }

    public List<Map> select(String namaRapatKerja) throws Exception {
        String sql = "SELECT * FROM ppmk.rapatKerja WHERE namaRapatKerja=?";
        return ClassConnection.getJdbc().queryForList(sql, new Object[]{namaRapatKerja});
    }

    public List<Map> select(int kodeRapatKerja, String namaRapatKerja) throws Exception {
        String sql = "SELECT * FROM ppmk.rapatKerja WHERE kodeRapatKerja<>? AND namaRapatKerja=?";
        return ClassConnection.getJdbc().queryForList(sql, new Object[]{Integer.valueOf(kodeRapatKerja), namaRapatKerja});
    }

    // revisied by : dewi (BAPSI)
    public boolean cekDataTabel(String table, String[] field, String[] value) {
        cekTabel obj = new cekTabel();
        cekTabelDAO dao = new cekTabelDAOImpl();
        List lsNamaField = new ArrayList();
        List lsValueField = new ArrayList();
        for (int i = 0; i < field.length; i++) {
            lsNamaField.add(field[i].toString());
            lsValueField.add(value[i].toString());
        }
        obj.setNamaTabel(table);
        obj.setNamaField(lsNamaField);
        obj.setValueField(lsValueField);
        if (dao.cekTabel(obj)) {
            return true;
        } else {
            return false;
        }
    }
    //

}
